//
//  IComponentProtocol.h
//  DesignMode
//
//  Created by wangzhipan on 2024/11/7.
//

#ifndef IComponentProtocol_h
#define IComponentProtocol_h
#import <UIKit/UIKit.h>
@protocol IComponentLifecycle <NSObject>
/*
 当组件被加入 root树时，开始有生命周期
 
 将要加入root树：  componentWillLoad
 已经加入root树：  componentDidLoad
 将要从root树移除：componentWillUnload
 已经从root树移除：componentDidUnload
 */
@required
- (void)componentWillLoad;
- (void)componentDidLoad;
- (void)componentWillUnload;
- (void)componentDidUnload;
@end

@protocol IComponent <NSObject>
@required
@property (nonatomic, assign, readonly) NSUInteger priority;
@property (nonatomic, weak, nullable, readonly) id<IComponent>superComponent;
@property (nonatomic, copy, readonly, nonnull) NSString *componentId;
@property (nonatomic, assign, readonly) BOOL isLoaded;
- (nonnull instancetype)initWithComponentId:(nonnull NSString *)componentId priority:(NSUInteger)priority;
- (nonnull instancetype)initWithRootView:(nonnull UIView *)rootView;
- (nullable id<IComponent>)rootComponent;
- (void)addComponent:(nonnull id<IComponent>)component;
- (void)removeComponent:(nonnull id<IComponent>)component;
- (nullable id<IComponent>)findForComponentId:(nonnull NSString *)componentId;
@end

@protocol IComponentUI <NSObject>
@required
@property (nonatomic, strong, nullable) UIView *componentView;
- (void)layoutInSuperComponentView:(nonnull UIView *)superView;
- (BOOL)isLazyLoadUI;
- (nullable UIView *)lazyLoadView;
- (void)loadComponentViewIfNeed:(nullable void(^)(UIView * _Nonnull componentView))completed;
@end


@protocol IZYComponentRegister <NSObject>
@property (nonatomic, copy, nonnull) NSString *componentId;
@property (nonatomic, assign) NSUInteger priority;
- (nonnull instancetype)initWithComponentId:(nonnull NSString *)componentId priority:(NSUInteger)priority;
- (nonnull id<IComponent>)generateComponent;
@end

#endif /* IComponentProtocol_h */
